package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC593 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {

        public boolean validSquare(int[] p1, int[] p2, int[] p3, int[] p4) {
            return validSquarePart(p1, p2, p3, p4) && validSquarePart(p2, p1, p3, p4) && validSquarePart(p4, p1, p2, p3);
        }

        public boolean validSquarePart(int[] p1, int[] p2, int[] p3, int[] p4) {
            long len1 = getLen(p1, p2);
            long len2 = getLen(p1, p3);
            long len3 = getLen(p1, p4);

            return (len1 != 0 && len1 == len2 && len3 == 2 * len1) || (len1 != 0 && len1 == len3 && len2 == 2 * len1) || (len2 != 0 && len2 == len3 && len1 == 2 * len2);
        }

        public long getLen(int[] p1, int[] p2) {
            return 1L * (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]);
        }
    }

    public void run() {
        Solution solution = new Solution();
//        p1 = [0,0], p2 = [1,1], p3 = [1,0], p4 = [0,1]
//        int[] p1 = {0, 0}, p2 = {5, 0}, p3 = {5, 4}, p4 = {0, 4};
//        int[] p1 = {0, 0}, p2 = {1, 1}, p3 = {1, 0}, p4 = {0, 1};
//        int[] p1 = {0, 1}, p2 = {1, 2}, p3 = {0, 2}, p4 = {0, 0};

        int[] p1 = {1, 1}, p2 = {0, 1}, p3 = {1, 2}, p4 = {0, 0};
        System.out.println(solution.validSquare(p1, p2, p3, p4));
    }

    public static void main(String[] args) throws Exception {
        LC593 an = new LC593();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
